import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';

import { getSimpleUserList } from '#/api/system/user';
import { getRangePickerDefaultProps } from '#/utils';

import { $t } from '#/locales';

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'userId',
      label: $t('views.ai.common.user'),
      component: 'ApiSelect',
      componentProps: {
        api: getSimpleUserList,
        labelField: 'nickname',
        valueField: 'id',
      },
    },
    {
      fieldName: 'title',
      label: $t('views.ai.music.manager.title'),
      component: 'Input',
    },
    {
      fieldName: 'status',
      label: $t('common.status'),
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_TYPE.AI_MUSIC_STATUS, 'number'),
      },
    },
    {
      fieldName: 'generateMode',
      label: $t('views.ai.music.manager.generateMode'),
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_TYPE.AI_GENERATE_MODE, 'number'),
      },
    },
    {
      fieldName: 'createTime',
      label: $t('common.createTime'),
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'publicStatus',
      label: $t('views.ai.music.manager.publicStatus'),
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING, 'boolean'),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'id',
      title: $t('views.common.id'),
      minWidth: 180,
      fixed: 'left',
    },
    {
      title: $t('views.ai.music.manager.title'),
      minWidth: 180,
      fixed: 'left',
      field: 'title',
    },
    {
      minWidth: 180,
      title: $t('views.ai.common.user'),
      slots: { default: 'userId' },
    },
    {
      field: 'status',
      title: $t('common.status'),
      minWidth: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.AI_MUSIC_STATUS },
      },
    },
    {
      field: 'model',
      title: $t('views.ai.common.modelName'),
      minWidth: 180,
    },
    {
      title: $t('views.ai.music.manager.content'),
      minWidth: 180,
      slots: { default: 'content' },
    },
    {
      field: 'duration',
      title: $t('views.ai.music.manager.duration'),
      minWidth: 130,
    },
    {
      field: 'prompt',
      title: $t('views.ai.music.manager.prompt'),
      minWidth: 180,
    },
    {
      field: 'lyric',
      title: $t('views.ai.music.manager.lyric'),
      minWidth: 180,
    },
    {
      field: 'gptDescriptionPrompt',
      title: $t('views.ai.music.manager.gptDescriptionPrompt'),
      minWidth: 180,
    },
    {
      field: 'generateMode',
      title: $t('views.ai.music.manager.generateMode'),
      minWidth: 110,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.AI_GENERATE_MODE },
      },
    },
    {
      field: 'tags',
      title: $t('views.ai.music.manager.tags'),
      minWidth: 180,
      cellRender: {
        name: 'CellTags',
      },
    },
    {
      minWidth: 100,
      title: $t('views.ai.music.manager.publicStatus'),
      slots: { default: 'publicStatus' },
    },
    {
      field: 'taskId',
      title: $t('views.ai.music.manager.taskId'),
      minWidth: 180,
    },
    {
      field: 'errorMessage',
      title: $t('views.ai.music.manager.errorMessage'),
      minWidth: 180,
    },
    {
      field: 'createTime',
      title: $t('common.createTime'),
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      title: $t('common.action'),
      width: 130,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
